﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Server.Struct
{
    class SyncRootHeap<T> : RootHeap<T>
    {
        System.Threading.Semaphore locker;

        public SyncRootHeap():base()
        {
            locker = new System.Threading.Semaphore(1, 1);
        }

        public SyncRootHeap(Func<T, T, bool> compare):base(compare)
        {
            locker = new System.Threading.Semaphore(1, 1);
        }

        public override T Peek()
        {
            locker.WaitOne();
            T t = base.Peek();
            locker.Release();
            return t;
        }

        public override T Pop()
        {
            locker.WaitOne();
            T t = base.Pop();
            locker.Release();
            return t;
        }

        public override void Push(T item)
        {
            locker.WaitOne();
            base.Push(item);
            locker.Release();
        }

    }
}
